package com.ftg.youx.controller;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ftg.youx.entity.ProItem;
import com.ftg.youx.service.IProItemService;
import com.ftg.youx.tools.R;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author kangjx
 * @since 2024-11-11
 */
@RestController
@RequestMapping("/proItem")
public class ProItemController {

    @Resource
    private IProItemService proItemService;

    @GetMapping("/list")
    public String list(@RequestParam(value = "name",required = false) String name,
                  @RequestParam("page") Integer page,
                  @RequestParam("pageSize") Integer pageSize
    ){
        IPage<ProItem> itemIPage = new Page<>(page, pageSize);
        QueryWrapper<ProItem> query = new QueryWrapper<>();
        if( name != null && !name.isEmpty() ){
            query.likeRight("name",name);
        }
       return  JSON.toJSONString(R.ok(proItemService.page(itemIPage,query)));
    }

    @GetMapping("/getUserInfo")
    public String getUserInfo(@RequestParam("page") Integer page,
                              @RequestParam("size") Integer size,
                              @RequestParam(value = "name", required = false) String name){
        return proItemService.getUserInfo(page,size,name);
    }

}
